package com.zhiche.lisa.bms.controller.pay;


import com.baomidou.mybatisplus.plugins.Page;
import com.zhiche.lisa.bms.dao.model.pay.PayAffirm;
import com.zhiche.lisa.bms.dao.model.price.PriceIncoming;
import com.zhiche.lisa.bms.pojo.vo.pay.PayAffirmDetailVO;
import com.zhiche.lisa.bms.pojo.vo.pay.PayAffirmPageVO;
import com.zhiche.lisa.bms.pojo.vo.pay.PayAffirmVO;
import com.zhiche.lisa.bms.service.pay.PayAffirmService;
import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 付款确认
 * </p>
 *
 * @author WangShuiJin
 * @since 2018-10-11
 */
@RestController
@RequestMapping("/payAffirm")
@Api(value = "/payAffirm", description = "付款确认接口", tags = {"付款确认接口"})
public class PayAffirmController {
    private static final Logger LOGGER = LoggerFactory.getLogger(PayAffirmController.class);
    @Autowired
    private PayAffirmService payAffirmService;

    @PostMapping(value = "/insertPayAffirm")
    @ApiOperation(value = "新增付款确认", notes = "新增付款确认", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = PriceIncoming.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<String> insertPayAffirm(@RequestBody PayAffirmDetailVO vo) {
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            payAffirmService.insertPayAffirm(vo, true);
        } catch (BaseException e) {
            LOGGER.error("/PayAffirmController.insertPayAffirm ERROR:{} ", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/PayAffirmController.insertPayAffirm ERROR:{} ", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/updatePayAffirm")
    @ApiOperation(value = "修改付款确认", notes = "修改付款确认", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = PriceIncoming.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<String> updatePayAffirm(@RequestBody PayAffirmDetailVO vo) {
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            payAffirmService.updatePayAffirm(vo);
        } catch (BaseException e) {
            LOGGER.error("/PayAffirmController.updatePayAffirm ERROR:{} ", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/PayAffirmController.updatePayAffirm ERROR:{} ", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/deletePayAffirm")
    @ApiOperation(value = "删除付款确认", notes = "删除付款确认", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = PriceIncoming.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<String> deletePayAffirm(@RequestBody List<Long> ids) {
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            payAffirmService.deletePayAffirm(ids);
        } catch (BaseException e) {
            LOGGER.error("/PayAffirmController.deletePayAffirm ERROR:{} ", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/PayAffirmController.deletePayAffirm ERROR:{} ", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @GetMapping(value = "/getPayAffirmDetailByID")
    @ApiOperation(value = "根据付款确认主键ID，得到付款确认旗下的明细", notes = "根据付款确认主键ID，得到付款确认旗下的明细", httpMethod = "GET")
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = PriceIncoming.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<PayAffirmVO> getPayAffirmDetailByID(@RequestParam Long id) {
        RestfulResponse<PayAffirmVO> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            PayAffirmVO resultData = payAffirmService.getPayAffirmDetailByID(id);
            result.setData(resultData);
        } catch (BaseException e) {
            LOGGER.error("/PayAffirmController.getPayAffirmDetailByID ERROR: {} ", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/PayAffirmController.getPayAffirmDetailByID ERROR: {} ", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/queryPayAffirmPage")
    @ApiOperation(value = "查询付款确认列表（分页）", notes = "查询付款确认列表（分页）", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = PriceIncoming.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<PayAffirmPageVO>> queryPayAffirmPage(@RequestBody Page<PayAffirm> page) {
        RestfulResponse<Page<PayAffirmPageVO>> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            Page<PayAffirmPageVO> resultData = payAffirmService.queryPayAffirmPage(page);
            result.setData(resultData);
        } catch (BaseException e) {
            LOGGER.error("/PayAffirmController.queryPayAffirmPage ERROR: {}", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/PayAffirmController.queryPayAffirmPage ERROR: {}", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/verifyPayAffirm")
    @ApiOperation(value = "付款确认，审核", notes = "付款确认，审核", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = PriceIncoming.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<String> verifyPayAffirm(@RequestBody List<Long> ids) {
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            payAffirmService.verifyPayAffirm(ids);
        } catch (BaseException e) {
            LOGGER.error("/PayAffirmController.verifyPayAffirm ERROR: {} ", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/PayAffirmController.verifyPayAffirm ERROR: {} ", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }

    @PostMapping(value = "/cancelVerifyPayAffirm")
    @ApiOperation(value = "付款确认，取消审核", notes = "付款确认，取消审核", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = PriceIncoming.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<String> cancelVerifyPayAffirm(@RequestBody List<Long> ids) {
        RestfulResponse<String> result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            payAffirmService.cancelVerifyPayAffirm(ids);
        } catch (BaseException e) {
            LOGGER.error("/PayAffirmController.cancelVerifyPayAffirm ERROR: {} ", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/PayAffirmController.cancelVerifyPayAffirm ERROR:{} ", e.getMessage());
            result = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }
}